package cn.wxq.daily.empdailymgforserve.controller;
import cn.wxq.daily.empdailymgforserve.domain.WorkReport;
import cn.wxq.daily.empdailymgforserve.model.Result;
import cn.wxq.daily.empdailymgforserve.model.StatusCode;
import cn.wxq.daily.empdailymgforserve.service.WorkReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@CrossOrigin //跨越处理
@RestController
@RequestMapping("/workReport")
@Api(value = "WorkReportController|工作汇报控制器")
public class WorkReportController {
    @Autowired
    private WorkReportService workReportService;

    /**
     * 条件查询
     * @param workReport
     * @return
     */
    @RequestMapping(value = "/findByPageReport", method = RequestMethod.POST)
    @ApiOperation(value = "按条件查询")
    public Result findByPageReport(WorkReport workReport) {
        List<WorkReport> workReports = workReportService.findAllReport(workReport);
        if (workReports != null) {
            return new Result(true, StatusCode.OK, "获取成功", workReports);
        } else {
            return new Result(false, StatusCode.ERROR, "返回数据异常");
        }
    }


    /**
     * 新增
     * @param workReport
     * @return
     */
    @RequestMapping(value = "/saveReport", method = RequestMethod.POST)
    @ApiOperation(value = "新增")
    public Result saveReport(WorkReport workReport) {
        int row = workReportService.insertReport(workReport);
        return new Result(true, StatusCode.OK, "新增成功");
    }

    /**
     * 修改
     * @param workReport
     * @return
     */
    @RequestMapping(value = "/updateReport", method = RequestMethod.POST)
    @ApiOperation(value = "修改")
    public Result updateReport(WorkReport workReport) {
        int row = workReportService.updateReport(workReport);
        return new Result(true, StatusCode.OK, "修改成功");
    }
    /**
     * 删除
     * @param workId
     * @return
     */
    @RequestMapping(value = "/deleteReportById", method = RequestMethod.POST)
    @ApiOperation(value = "删除")
    public Result deleteReportById(int  workId) {
        int row = workReportService.deleteReportById(workId);
        return new Result(true, StatusCode.OK, "删除成功");
    }
}
